//
//  HWInviteRecordController.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/9/15.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWInviteRecordController: HWBaseViewController {
    var tableView:UITableView!
    var tableViewProtocol = HWInviteRecordProtocol()
    var httpManager = HWInviteHttpManger()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initUI()
        
        initFrame()
        
        loadData()
        
    }

}

extension HWInviteRecordController {
    private func initUI() -> Void {
        
        navigationView.titleLabel.text = "发放记录"
        navigationView.backButton.setImage(UIImage(named: "navBackButton"), for: .normal)
        
        tableView = UITableView.init(frame: CGRect.zero, style: UITableView.Style.plain)
        tableView.delegate = tableViewProtocol
        tableView.dataSource = tableViewProtocol
        tableView.backgroundColor = .white
        tableView.separatorStyle = .none
        tableView.rowHeight = UITableView.automaticDimension
        tableView.estimatedRowHeight = 40
        tableView.estimatedSectionHeaderHeight = 0
        tableView.estimatedSectionFooterHeight = 0
        tableView.showsVerticalScrollIndicator = false
        view.addSubview(tableView)
        tableView.contentInsetAdjustmentBehavior = .never
        tableView.ly_emptyView = LYEmptyView.empty(withImageStr: "", titleStr: "", detailStr: "暂无数据")
        tableView.ly_emptyView.contentViewOffset = -40
        if #available(iOS 15.0, *) {
            self.tableView.sectionHeaderTopPadding = 0
        } else {
            // Fallback on earlier versions
        }
    }
    
    private func initFrame() -> Void {
        tableView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(navigationView.snp.bottom)
        }
    }
}

extension HWInviteRecordController {
    func loadData() -> Void {
        self.httpManager.getnviteSendRecord { models in
            self.tableViewProtocol.models = models
            self.tableView.reloadData()
        } failure: { errorString in
            self.view.showHUD(title: errorString)
        }

    }
}
